package com.ctshk.sapp.ship.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.ship.dto.ShipProductDTO;
import com.ctshk.rpc.ship.dto.ShipRouteDTO;
import com.ctshk.rpc.ship.req.ShipProductReq;
import com.ctshk.rpc.ship.req.ShipRoutePageReq;
import com.ctshk.rpc.ship.req.ShipRouteReq;
import com.ctshk.rpc.ship.service.IShipRouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 船-航线表 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-05
 */
@Api(value = "航线相关",tags = "航线相关")
@RestController
@RequestMapping("/ship-route")
public class ShipRouteController extends BaseController {

    @DubboReference
    private IShipRouteService iShipRouteService;

    @ApiOperation(value = "航线集合查询", notes = "航线集合查询")
    @PostMapping(value = "/query-list")
    public Result<PageResponse<ShipRouteDTO>> queryList(@RequestBody @Valid ShipRoutePageReq req) {
        return Result.success(iShipRouteService.queryShipRouteList(req));
    }

    @ApiOperation(value = "航线查询", notes = "航线查询")
    @PostMapping(value = "/query-detail")
    public Result<ShipRouteDTO> queryDetail(@RequestBody @Valid ShipRoutePageReq req) {
        return iShipRouteService.queryShipRouteDetail(req);
    }

    @ApiOperation(value="新增航线", notes="新增航线")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增航线", operDesc = "新增航线")
    @PostMapping("/save")
    public Result saveBusProduct(@RequestBody @Valid ShipRouteReq shipRouteReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipRouteService.saveShipRoute(shipRouteReq,user);
    }

    @ApiOperation(value = "修改航线", notes = "修改航线")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改航线", operDesc = "修改航线")
    @PostMapping("/update")
    public Result updateShipRoute(@RequestBody @Valid ShipRouteReq shipRouteReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipRouteService.updateShipRoute(shipRouteReq, user);
    }

    @ApiOperation(value = "修改狀態", notes = "修改狀態")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改狀態", operDesc = "修改狀態")
    @PostMapping("/updateStatus")
    public Result updateShipRouteStatus(@RequestBody @Valid ShipRouteReq shipRouteReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipRouteService.updateShipRouteStatus(shipRouteReq, user);
    }

}
